package com.woniu40.petai_user.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import java.io.FileWriter;
import java.io.IOException;

/**
 * 类名：AlipayConfig
 * 功能：基础配置类
 * 详细：设置账户有关信息级返回路径
 */

@Configuration
public class AlipayConfig {

    //在这里配置基本信息

    //应用ID。您的APPID，收款账号既是您的APPID对应支付宝账号
    public static String app_id;

    //        商户私钥，您的PKC88格式RSA2私钥
    public static String merchant_private_key;

    //        支付宝公钥，查看地址：https://openhome.apipay.com/platform/
    public static String alipay_public_key;

    public static String notify_url;

    public static String return_url;

    public static String sign_type;

    public static String charset;

    public static String gatewayUrl;

    public static String log_path;

    @Value("${pay.alipay.app_id}")
    public void setApp_id(String app_id) {
        AlipayConfig.app_id = app_id;
    }

    @Value("${pay.alipay.merchant_private_key}")
    public void setMerchant_private_key(String merchant_private_key) {
        AlipayConfig.merchant_private_key = merchant_private_key;
    }

    @Value("${pay.alipay.alipay_public_key}")
    public void setAlipay_public_key(String alipay_public_key) {
        AlipayConfig.alipay_public_key = alipay_public_key;
    }

    @Value("${pay.alipay.notify_url}")
    public void setNotify_url(String notify_url) {
        AlipayConfig.notify_url = notify_url;
    }

    @Value("${pay.alipay.return_url}")
    public void setReturn_url(String return_url) {
        AlipayConfig.return_url = return_url;
    }

    @Value("${pay.alipay.sign_type}")
    public void setSign_type(String sign_type) {
        AlipayConfig.sign_type = sign_type;
    }

    @Value("${pay.alipay.charset}")
    public void setCharset(String charset) {
        AlipayConfig.charset = charset;
    }

    @Value("${pay.alipay.gatewayUrl}")

    public void setGatewayUrl(String gatewayUrl) {
        AlipayConfig.gatewayUrl = gatewayUrl;
    }

    @Value("${pay.alipay.log_path}")

    public void setLog_path(String log_path) {
        AlipayConfig.log_path = log_path;
    }

    public static void logResult(String sWord) {
        FileWriter writer = null;
        try {
            writer = new FileWriter(log_path + "alipay_log_" + System.currentTimeMillis() + ".txt");
            writer.write(sWord);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (writer != null) {
                try {
                    writer.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}


